package com.city.justlisten.controller;

import com.city.justlisten.service.AdminService;
import com.city.justlisten.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA.
 * User: Cheng
 * Date: 2021/1/28
 * Time: 22:35
 * Description: No Description
 */
@RestController
@RequestMapping("/admin")
@CrossOrigin(allowCredentials = "true", allowedHeaders = "*")
public class AdminController {

    @Autowired
    private AdminService adminService;

    @PostMapping("/login/status")
    public Result validationPassword(HttpSession session, @RequestParam String name, @RequestParam String password){
        Boolean aBoolean = adminService.validationPassword(name, password);
        if (aBoolean){
            session.setAttribute("name",name);
            return Result.ok().message("登录成功！");
        }
        return Result.error().message("用户名或密码错误，请重新登录！");
    }

}
